home *** CD-ROM | disk | FTP | other *** search
/ Young Minds / Young Minds Interactive CD-ROM.ISO / rogue / init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-05-13  |  4.9 KB  |  278 lines

  1. /*
  2.  * init.c
  3.  *
  4.  * This source herein may be modified and/or distributed by anybody who
  5.  * so desires, with the following restrictions:
  6.  *    1.)  No portion of this notice shall be removed.
  7.  *    2.)  Credit shall not be taken for the creation of this source.
  8.  *    3.)  This code is not to be traded, sold, or used for personal
  9.  *         gain or profit.
  10.  *
  11.  */
  12.  
  13. #ifndef CURSES
  14. #include <curses.h>
  15. #endif CURSES
  16. #include <stdio.h>
  17. #include "rogue.h"
  18.  
  19. char login_name[30];
  20. char *nick_name = "";
  21. char *restore_file = 0;
  22. boolean cant_int = 0, did_int = 0, score_only, init_curses = 0;
  23. boolean save_is_interactive = 1;
  24. boolean ask_quit = 1, show_skull = 1;
  25. char *error_file = "rogue.esave";
  26. char *byebye_string = "Okay, bye bye!";
  27.  
  28. extern char *fruit;
  29. extern char *save_file;
  30. extern short party_room, party_counter;
  31. extern boolean jump;
  32.  
  33. init(argc, argv)
  34. int argc;
  35. char *argv[];
  36. {
  37.     char *pn;
  38.     int seed;
  39.  
  40.     do_args(argc, argv);
  41.     do_opts();
  42.  
  43.     pn = md_gln();
  44.     if ((!pn) || (strlen(pn) >= 30)) {
  45.         clean_up("Hey!  Who are you?");
  46.     }
  47.     (void) strcpy(login_name, pn);
  48.  
  49.     if (!score_only && !restore_file) {
  50.         printf("Hello %s, just a moment while I dig the dungeon...",
  51.         ((nick_name[0]) ? nick_name : login_name));
  52.         fflush(stdout);
  53.     }
  54.  
  55.     initscr();
  56.     if ((LINES < DROWS) || (COLS < DCOLS)) {
  57.         clean_up("must be played on 24 x 80 screen");
  58.     }
  59.     start_window();
  60.     init_curses = 1;
  61.  
  62.     md_heed_signals();
  63.  
  64.     if (score_only) {
  65.         put_scores((object *) 0, 0);
  66.     }
  67.     seed = md_gseed();
  68.     (void) srrandom(seed);
  69.     if (restore_file) {
  70.         restore(restore_file);
  71.         return(1);
  72.     }
  73.     mix_colors();
  74.     get_wand_and_ring_materials();
  75.     make_scroll_titles();
  76.  
  77.     level_objects.next_object = 0;
  78.     level_monsters.next_monster = 0;
  79.     player_init();
  80.     party_counter = get_rand(1, PARTY_TIME);
  81.     ring_stats(0);
  82.     return(0);
  83. }
  84.  
  85. player_init()
  86. {
  87.     object *obj;
  88.  
  89.     rogue.pack.next_object = 0;
  90.  
  91.     obj = alloc_object();
  92.     get_food(obj, 1);
  93.     (void) add_to_pack(obj, &rogue.pack, 1);
  94.  
  95.     obj = alloc_object();        /* initial armor */
  96.     obj->what_is = ARMOR;
  97.     obj->which_kind = RINGMAIL;
  98.     obj->class = RINGMAIL+2;
  99.     obj->is_protected = 0;
  100.     obj->d_enchant = 1;
  101.     (void) add_to_pack(obj, &rogue.pack, 1);
  102.     do_wear(obj);
  103.  
  104.     obj = alloc_object();        /* initial weapons */
  105.     obj->what_is = WEAPON;
  106.     obj->which_kind = MACE;
  107.     obj->damage = "2d3";
  108.     obj->hit_enchant = obj->d_enchant = 1;
  109.     obj->identified = 1;
  110.     (void) add_to_pack(obj, &rogue.pack, 1);
  111.     do_wield(obj);
  112.  
  113.     obj = alloc_object();
  114.     obj->what_is = WEAPON;
  115.     obj->which_kind = BOW;
  116.     obj->damage = "1d2";
  117.     obj->hit_enchant = 1;
  118.     obj->d_enchant = 0;
  119.     obj->identified = 1;
  120.     (void) add_to_pack(obj, &rogue.pack, 1);
  121.  
  122.     obj = alloc_object();
  123.     obj->what_is = WEAPON;
  124.     obj->which_kind = ARROW;
  125.     obj->quantity = get_rand(25, 35);
  126.     obj->damage = "1d2";
  127.     obj->hit_enchant = 0;
  128.     obj->d_enchant = 0;
  129.     obj->identified = 1;
  130.     (void) add_to_pack(obj, &rogue.pack, 1);
  131. }
  132.  
  133. clean_up(estr)
  134. char *estr;
  135. {
  136.     if (save_is_interactive) {
  137.         if (init_curses) {
  138.             move(DROWS-1, 0);
  139.             refresh();
  140.             stop_window();
  141.         }
  142.         printf("\n%s\n", estr);
  143.     }
  144.     md_exit(0);
  145. }
  146.  
  147. start_window()
  148. {
  149.     crmode();
  150.     noecho();
  151.     nonl();
  152.     md_control_keybord(0);
  153. }
  154.  
  155. stop_window()
  156. {
  157.     endwin();
  158.     md_control_keybord(1);
  159. }
  160.  
  161. byebye()
  162. {
  163.     md_ignore_signals();
  164.     if (ask_quit) {
  165.         quit(1);
  166.     } else {
  167.         clean_up(byebye_string);
  168.     }
  169.     md_heed_signals();
  170. }
  171.  
  172. onintr()
  173. {
  174.     md_ignore_signals();
  175.     if (cant_int) {
  176.         did_int = 1;
  177.     } else {
  178.         check_message();
  179.         message("interrupt", 1);
  180.     }
  181.     md_heed_signals();
  182. }
  183.  
  184. error_save()
  185. {
  186.     save_is_interactive = 0;
  187.     save_into_file(error_file);
  188.     clean_up("");
  189. }
  190.  
  191. do_args(argc, argv)
  192. int argc;
  193. char *argv[];
  194. {
  195.     short i, j;
  196.  
  197.     for (i = 1; i < argc; i++) {
  198.         if (argv[i][0] == '-') {
  199.             for (j = 1; argv[i][j]; j++) {
  200.                 switch(argv[i][j]) {
  201.                 case 's':
  202.                     score_only = 1;
  203.                     break;
  204.                 }
  205.             }
  206.         } else {
  207.             restore_file = argv[i];
  208.         }
  209.     }
  210. }
  211.  
  212. do_opts()
  213. {
  214.     char *eptr;
  215.  
  216.     if (eptr = md_getenv("ROGUEOPTS")) {
  217.         for (;;) {
  218.             while ((*eptr) == ' ') {
  219.                 eptr++;
  220.             }
  221.             if (!(*eptr)) {
  222.                 break;
  223.             }
  224.             if (!strncmp(eptr, "fruit=", 6)) {
  225.                 eptr += 6;
  226.                 env_get_value(&fruit, eptr, 1);
  227.             } else if (!strncmp(eptr, "file=", 5)) {
  228.                 eptr += 5;
  229.                 env_get_value(&save_file, eptr, 0);
  230.             } else if (!strncmp(eptr, "nojump", 6)) {
  231.                 jump = 0;
  232.             } else if (!strncmp(eptr, "name=", 5)) {
  233.                 eptr += 5;
  234.                 env_get_value(&nick_name, eptr, 0);
  235.             } else if (!strncmp(eptr, "noaskquit", 9)) {
  236.                 ask_quit = 0;
  237.             } else if (!strncmp(eptr, "noskull", 5) ||
  238.                     !strncmp(eptr,"notomb", 6)) {
  239.                 show_skull = 0;
  240.             }
  241.             while ((*eptr) && (*eptr != ',')) {
  242.                 eptr++;
  243.             }
  244.             if (!(*(eptr++))) {
  245.                 break;
  246.             }
  247.         }
  248.     }
  249. }
  250.  
  251. env_get_value(s, e, add_blank)
  252. char **s, *e;
  253. boolean add_blank;
  254. {
  255.     short i = 0;
  256.     char *t;
  257.  
  258.     t = e;
  259.  
  260.     while ((*e) && (*e != ',')) {
  261.         if (*e == ':') {
  262.             *e = ';';        /* ':' reserved for score file purposes */
  263.         }
  264.         e++;
  265.         if (++i >= 30) {
  266.             break;
  267.         }
  268.     }
  269.     if (!(*s = md_malloc(i + (add_blank ? 2 : 1)))) {
  270.         clean_up("cannot alloc() memory");
  271.     }
  272.     (void) strncpy(*s, t, i);
  273.     if (add_blank) {
  274.         (*s)[i++] = ' ';
  275.     }
  276.     (*s)[i] = '\0';
  277. }
  278.